/**
 *  Copyright (C) 2013  Piotr Szczepa�ski
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package edu.pw.elka.gtsna.community_detection;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import edu.pw.elka.gtsna.coalitionalgames.CoalitionalStructure;
import edu.pw.elka.gtsna.graph.Graph;
import edu.pw.elka.gtsna.graph_creator.GraphCommunityStructureReader;

/**
 * @author Piotr Lech Szczepa�ski
 * @author P.Szczepanski@ii.pw.edu.pl 
 *
 *	Community structure is a special case of coalition structure in the domain of graphs
 *	@see edu.pw.elka.gtsna.coalitionalgames.CoalitionalStructure
 */

// The Graph cs is coalitional structure
public class CommunityStructure extends CoalitionalStructure {
	
	public CommunityStructure(){
		
	}
	
	public CommunityStructure(GraphCommunityStructureReader reader){
		for(List<Integer> nodePartition: reader){
			addNode(nodePartition.get(0), nodePartition.get(1));
		}
	}
	
	public List<Set<Integer>> getCommunities(){
		return  getCoalitions();
	}
	
	public void addNode(int node, int partitionNumber){
		addAgent(node, partitionNumber);
	}
	
	public void addCommunity(Set<Integer> coalition){
		addCoalition(coalition);
	}
	
	public Collection<Integer> getCommunitiesNumbers() {
		return getStructersNumbers();
	}
	
	public Set<Integer> getNodesFromCommunity(Set<Integer> M){
		return getAgentsFromCoalitions(M);
	}
	
	public Set<Integer> getNodesCommunity(int a){
		return getAgentCoalition(a);
	}
	
	public Set<Integer> getCommunity(int number){
		return getCoalition(number);
	}
	
	public int getNodeCommunityNumber(int a){
		return getAgentCoalitionNumber(a);
	}
	
	// TODO
	public void removeCommunity(int c) {
		getCommunity(c).clear();
		coalitionNumbers.remove(c);
	}
	
//	public void printRFormat(Graph g){
//		System.out.println("***********");
//		
//		Map<Integer,Integer> map = new HashMap<Integer,Integer>();
//		for (int i=1; i<=g.getNumOfNodes();i++){
//			map.put(i, -1);
//		}
//		
//		int num = 1;
//		for (int node: g.getAllNodes()){
//			
//			if (map.get(getNodeCommunityNumber(node)) == -1 )
//			
//		//	System.out.print((getNodeCommunityNumber(i)+1)+",");
//		}
//		System.out.println("");
//		System.out.println("***********");
//	}
}
